home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / addpcx.zip / HERC.C < prev    next >
C/C++ Source or Header  |  1988-04-17  |  3KB  |  168 lines

  1. /*    HERC.c   - Video routines specific to the Hercules board.
  2. */
  3.  
  4. #include "lib.h"
  5. #include "vgr.h"
  6.  
  7. #define REG_INDEX   0x3b4
  8. #define REG_DATA    0x3b5
  9. #define REG_MODE    0x3b8
  10. #define REG_STATUS  0x3ba
  11. #define REG_CONFIG  0x3bf
  12.  
  13. int herc_mode();
  14. int herc_write_row();
  15. int herc_init();
  16. int herc_set_page();
  17. int herc_clear();
  18. int herc_clr_point();
  19. int herc_set_point();
  20. int herc_xor_point();
  21. int herc_get_point();
  22. int herc_null();
  23. int movmem();
  24. int peekb();
  25. int pokeb();
  26.  
  27.  
  28. static int herc_page = 0;
  29. static int (*herc_func[])() =
  30.     {  herc_init,      herc_clear,    herc_set_point,   herc_clr_point,
  31.        herc_xor_point, herc_get_point,herc_write_row,   herc_null,
  32.        herc_null,      herc_mode,     movmem, peekb, pokeb,
  33.        herc_set_page,  herc_null   };
  34.  
  35.  
  36. static unsigned char far * far *herc_column[2];
  37.  
  38.  
  39. static int herc_null()
  40. {
  41.     return ERROR;    /* do nothing */
  42. }
  43.  
  44.  
  45. int herc_set_page( page )
  46. int page;
  47. {
  48.     outportb( REG_MODE, (herc_page = !!page) ? 0x8a : 0x0a );
  49.     return OK;
  50. }
  51.  
  52.  
  53. int herc_clear()
  54. {
  55.     setmem( (herc_page ? BASE_HERC1 : BASE_HERC0), 0x8000, 0 );
  56.     return OK;
  57. }
  58.  
  59.  
  60. int herc_write_row( row, prow, nbytes )
  61. unsigned int nbytes, row;
  62. char *prow;
  63. {
  64.     movmem( prow, herc_column[herc_page][row], nbytes );
  65.     return OK;
  66. }
  67.  
  68.  
  69. int herc_init()
  70. {
  71.     unsigned int i,j;
  72.     void *malloc();
  73.  
  74.     VGR_HRES  = 720;
  75.     VGR_VRES  = 348;
  76.     VGR_NBPL  =  90;
  77.     VGR_NCOLORS = 2;
  78.  
  79.     if ( !herc_column[0] )
  80.        herc_column[0] = CASTUCFPP malloc( sizeof(uchar far *) * VGR_VRES );
  81.     if ( !herc_column[0] )
  82.        return ERROR;
  83.  
  84.     if ( !herc_column[1] )
  85.        herc_column[1] = CASTUCFPP malloc( sizeof(uchar far *) * VGR_VRES );
  86.  
  87.     if ( !herc_column[1] )
  88.     {  allocf( herc_column[0] );
  89.        return ERROR;
  90.     };
  91.  
  92.     for ( i = 0; i < VGR_VRES; i++ )
  93.     {   j = 0x2000 * (i & 0x03) + VGR_NBPL * (i >> 2);
  94.         herc_column[0][i] = CASTUCFP BASE_HERC0 + j;
  95.         herc_column[1][i] = CASTUCFP BASE_HERC1 + j;
  96.     };
  97.  
  98.     movmem( herc_func, vgr_func, sizeof(vgr_func) );
  99.     return OK;
  100. }
  101.  
  102.  
  103. int herc_set_point( x, y )
  104. unsigned int x, y;
  105. {
  106.     herc_column[herc_page][y][x>>3] |= (x >> 3);
  107. }
  108.  
  109.  
  110. int herc_clr_point( x, y )
  111. unsigned int x, y;
  112. {
  113.     herc_column[herc_page][y][x>>3] &= ~(x >> 3);
  114. }
  115.  
  116.  
  117. int herc_get_point( x, y )
  118. unsigned int x, y;
  119. {
  120.     return !!(herc_column[herc_page][y][x>>3] & (x >> 3));
  121. }
  122.  
  123.  
  124. int herc_xor_point( x, y )
  125. unsigned int x, y;
  126. {
  127.     herc_column[herc_page][y][x>>3] ^= (x >> 3);
  128. }
  129.  
  130.  
  131. int herc_mode( mode )
  132. int mode;
  133. {
  134.     int i;
  135.     static char setup[2][12] = {
  136.        { 0x35,0x2d,0x2e,0x07,0x5b,0x02,0x57,0x57,0x02,0x03,0x00,0x00 },
  137.        { 0x61,0x50,0x52,0x0f,0x19,0x06,0x19,0x19,0x02,0x0d,0x0b,0x0c }
  138.                                };
  139.  
  140.     if ( mode == MODE_TEXT0 )
  141.     {  outportb( REG_CONFIG, 0 );
  142.        outportb( REG_MODE,   0 );
  143.        for ( i=0; i < 12; i++ )
  144.        {  outportb( REG_INDEX, i );
  145.           outportb( REG_DATA,  setup[1][i] );
  146.        };
  147.        outportb( REG_MODE, 0x28 );
  148.        vgr_mode(3);   /* the cursor is missing if I don't do this... */
  149.        return OK;
  150.     };
  151.  
  152.     if ( mode == MODE_APA1 )
  153.     {  outportb( REG_CONFIG, 3 );
  154.        outportb( REG_MODE,   2 );
  155.        for ( i=0; i < 12; i++ )
  156.        {  outportb( REG_INDEX, i );
  157.           outportb( REG_DATA,  setup[0][i] );
  158.        };
  159.        setmem( BASE_HERC0, 0x8000, 0 );
  160.        setmem( BASE_HERC1, 0x8000, 0 );
  161.        herc_set_page( 1 );
  162.        return OK;
  163.     };
  164.  
  165.     return ERROR;
  166. }
  167.  
  168.